package com.xzl.xep.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xzl.xep.common.utils.DateUtil;
import com.xzl.xep.dao.ReportDao;
import com.xzl.xep.pojo.ReportDto;
import com.xzl.xep.pojo.Sale;
import com.xzl.xep.service.ReportService;

@Service
public class ReportServiceImpl extends BaseServiceImpl implements ReportService {

	@Resource
	private  ReportDao report;

	@Override
	public ReportDto getTotalDto(Long companyId) {
		
		return report.getTotalDto(companyId);
	}

	@Override
	public ReportDto getTodayDto(Long companyId) {
		
		return report.getTodayDto(companyId);
	}
	
	@Override
	public List<Sale> getSales(Long companyId) {
	
		
		StringBuffer sb = new StringBuffer();
		sb.append(" from Sale where 1=1");
		if(companyId != null && companyId > 0)
			sb.append(" and companyId = ").append(companyId);
		
		sb.append(" order by modifyTime desc");
		
		return dao.selectByHql(sb.toString());
		
	}

	@Override
	public Double getSpend(Long companyId, Date start, Date end) {
		
		return report.getSpend(companyId,start,end);
	}

	@Override
	public Double getCredit(Long companyId, Date start, Date end) {
		
		return report.getCredit(companyId,start,end);
	}

	@Override
	public Double getCustomerSpend(Long companyId, Date start, Date end) {
	
		return report.getCustomerSpend(companyId,start,end);
	}

	@Override
	public Integer getCustomerCounts(Long companyId, Date start, Date end) {
	
		return report.getCustomerCounts(companyId,start,end);
	}

	@Override
	public List<Sale> getTotalSales(Long companyId) {
		
		StringBuffer sb = new StringBuffer();
		sb.append(" from Sale where 1=1");
		if(companyId != null && companyId > 0)
			sb.append(" and companyId = ").append(companyId);
		
		sb.append(" and createTime >= '").append(DateUtil.getCurrentYMDstr()).append(" 00:00:00' ");
		
		sb.append(" and createTime <= '").append(DateUtil.getCurrentYMDstr()).append(" 23:59:59' ");
		
		
		sb.append(" order by modifyTime desc");
		
		return dao.selectByHql(sb.toString());
	}

	
	
}
